
function getContextPath(){
	var pathName = document.location.pathname;
    var index = pathName.substr(0).indexOf("/");
    var path = pathName.substr(0,index+1);
    return path;
}

function parseUrl(url) {
    var a =  document.createElement('a');
    a.href = url;
    return {
        source: url,
        protocol: a.protocol.replace(':',''),
        host: a.hostname,
        port: a.port,
        query: a.search,
        params: (function(){
            var ret = {},
                seg = a.search.replace(/^\?/,'').split('&'),
                len = seg.length, i = 0, s;
            for (;i<len;i++) {
                if (!seg[i]) { continue; }
                s = seg[i].split('=');
                ret[s[0]] = s[1];
            }
            return ret;
        })(),
        file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
        hash: a.hash.replace('#',''),
        path: a.pathname.replace(/^([^\/])/,'/$1'),
        relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
        segments: a.pathname.replace(/^\//,'').split('/')
    };
}


function imageLoadError(){
	var path = window.parent.servicePath;
	$('img').error(function(){
	    $(this).attr('src' , path + '/images/marketing/img_load_error.png'); 
    });
}


function StringEmpty(content) {
	if (content == undefined || content == "" || content == null || content=="undefined" || content =="null") {
		return false;
	} else {
		return true;
	}
}
//获取url的参数
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null)
		return unescape(r[2]);
	return null;
}

function getChineseQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)
        return decodeURI(r[2]);
    return null;
}


//校验手机号码
function validatemobile(mobile) {
	var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	if (mobile.length == 0) {
		promptDialog('请输入手机号码！');
		return false;
	} else if (mobile.length != 11) {
		promptDialog('请输入有效的手机号码！');
		return false;
	} else if (!myreg.test(mobile)) {
		promptDialog('请输入有效的手机号码！');
		return false;
	} else {
		return true;
	}
} 
//判断content中是否包含 str
function isHaveStr(content,str){
	if(content.indexOf(str) != -1 ){
		return true;
    } else{
    	return false;
    }
}
//保留两位小数
function intToFloat(val){  
    return new Number(val).toFixed(2); 
}
//查询元素在list中的下标
function contains(a, obj) { 
  var i = a.length;   
  while (i--) { 
	  a[i]  
    if (a[i] === obj) {
      return i;   
    }   
  }   
  return false;   
} 
// str为字符串，oldStr为被替换字符，newStr为替换字符
function replaceAll(str,oldStr,newStr){
	var reg = "/"+oldStr+"/g";
	var val = str.replace(eval(reg),newStr);
	return val;
}